package com.ipc.app.biz.impl;

import com.ipc.app.biz.UserBiz;
import com.ipc.app.model.User;
import com.ipc.app.service.UserService;
import com.ipc.app.util.encrypt.MD5EntryptUtil;

/**
 * @author haijie.zhang
 * 
 */
public class UserBizImpl implements UserBiz {

	private UserService userService;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.ipc.app.biz.UserBiz#createUser(com.ipc.app.model.User)
	 */
	public void createUser(User user) {
		String password = user.getPassword();
		String encryptPWD = MD5EntryptUtil.getMD5Str(password);
		user.setPassword(encryptPWD);
		userService.createUser(user);
	}

	public User login(String mobile, String password) {
		// TODO:mobile及password空校验

		String encryptPassword = MD5EntryptUtil.getMD5Str(password);
		User user = userService.getUserByMobileAndPwd(mobile, encryptPassword);
		if (null == user)
			return null;
		String userID = user.getUserId();
		userService.updateLastLoginTime(userID);
		return user;
	}

	public User getUserByMobile(String mobile) {
		User user = userService.getUserByMobile(mobile);
		return user;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
